<#include "/common/layout.html">
<@body>
<div class="wrapper">
    <section class="content">
      <form class="form-horizontal" method="post" action="/system/me/updateUser" id="infoFrom" enctype="multipart/form-data">
          <div class="box-body">
            	<input type="hidden" value="${(sysUser.userId)!}" id="userId" name="userId">
            	<div class="form-group">
              		<label for="userName" class="col-sm-2 control-label">用户名称</label>
              		<div class="col-sm-10">
                		<input type="text" name="userName" value="${(sysUser.userName)!}" class="form-control" readonly="readonly" required>
              		</div>
            	</div>
            	<div class="form-group">
                	<label for="systemLogo" class="col-sm-2 control-label">用户头像</label>
                	<div class="col-sm-10">
	                	<input type="hidden" id="userImg" name="userImg" value="${(sysUser.userImg)!}">
						<div class="file-loading">
				            <input id="uploadImg" name="file" type="file" multiple>
				        </div>
                	</div>
              	</div>
              	<#if info??>
	            <div class="form-group">
	              	<div  class="alert alert-success alert-dismissible">
	          			<h4 style="margin-bottom: 0px;"><i class="fa fa-info"></i> ${info!}</h4>
        			</div>
            	</div>
            	</#if>
          </div>
        </form>
    </section>
</div>
</@body>
<script type="text/javascript">
	//单图上传
	$("#uploadImg").fileinput({
	    uploadUrl: '/system/sysfile/upload',
	    maxFileCount: 1,
	    autoReplace: true,
	    initialPreviewAsData: true,
	    initialPreview: ['${(sysUser.userImg)!}'],
	    layoutTemplates:{
	        actionUpload:'',//去除上传预览缩略图中的上传图片
	        actionDownload:'' ,//去除上传预览缩略图中的下载图标
	        actionDelete:'', //去除上传预览的缩略图中的删除图标
	    },
	}).on('fileuploaded', function (event, data, previewId, index) {
		var rsp = data.response;
		console.log("return fileUrl：" + rsp.fileUrl);
		console.log("reutrn fileName：" + rsp.fileName);
	    $('#userImg').val(rsp.fileUrl);
	}).on('filecleared', function(event) {
		$('#userImg').val('');
	})
	
	function submitHandler() {
		var userImg = $('#userImg').val();
		if(userImg == null || userImg == undefined || userImg == '') {
			layer.msg("请上传头像", {icon : 2});
			return false;
		}
		if ($("#infoFrom").validate().form()) {
			var formData = new FormData($("#infoFrom")[0]);
			$.ajax({
				url : $("#infoFrom").attr('action'),
				type : 'POST',
				data : formData,
				cache: false,
	            contentType: false,
	            processData: false,
	            dataType: 'json',
				beforeSend : function() {
					$.modal.loading("正在处理中，请稍后...");
					$.modal.disable();
				},
				success : function(data) {
					if (data.code == 200) {
						if (data.msg) {
							layer.msg(data.msg, {
								icon : 1
							});
						} else {
							layer.msg('修改成功', {
								icon : 1
							});
						}
						parent.layer.closeAll('iframe'); // 关闭当前frame
					} else {
						layer.msg(data.msg, {
							icon : 2
						});
						$.modal.closeLoading();
						$.modal.enable();
					}
				}
			});
		}
	}
</script>
